package com.hqyj.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.mapper.PaymentMapper;
import com.hqyj.mapper.UserMapper;
import com.hqyj.pojo.Payment;
import com.hqyj.pojo.User;
import com.hqyj.serviceInf.PaymentServiceInf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PaymentServiceImpl implements PaymentServiceInf {

    @Autowired
    private PaymentMapper paymentMapper;
    @Autowired
    private UserMapper userMapper;

//    全查

    public Map<String, Object> selectAll(int pageNum, int pageSize, String username) {
        //开启分页
        PageHelper.startPage(pageNum, pageSize);
        List<User> list = paymentMapper.selectAll(username);
        PageInfo<User> paymentPageInfo = new PageInfo<>(list);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("paymentPageInfo", paymentPageInfo);
        return map;
    }

    //    添加
    @Override
    public int insertPayment(Payment payment) {
        return paymentMapper.insertPayment(payment);
    }

    //    查询一个
    @Override
    public User selectPaymentId(User user) {
        List<User> users = userMapper.selectUser(1, 1, user.getUsername());
        System.out.println(users.get(0));
        return paymentMapper.selectPaymentId(users.get(0));
    }

    //    更改
    @Override
    public int updatePayment(Payment payment) {
        return paymentMapper.updatePayment(payment);
    }

    //    删除
    @Override
    public int deletePayment(int paymentid) {
        return paymentMapper.deletePayment(paymentid);
    }

    @Override
    public Payment selectPaymentByPaymentId(int paymentid) {
        return paymentMapper.selectPaymentByPaymentId(paymentid);
    }

    @Override
    public int insertOrderPayment(int orderid, int paymentid) {
        return paymentMapper.insertOrderPayment(orderid, paymentid);
    }

    @Override
    public List<Payment> selectPayment() {
        return null;
    }

//
//    @Override
//    public List<Payment> selectPayment() {
//        return paymentMapper.selectPaymentId();
//    }
}
